package network.protocol;
import game.engine.GSync;
import game.objects.GameObject;
import graphics.objects.GraphicsObject;

import java.util.Vector;

import network.RSocket;
import network.dataFormats.GroToGO;
import network.dataFormats.NetworkData;
import network.dataFormats.NetworkPackage;
import physics.Body;
import physics.joints.Joint;
import tools.id.IdObject;
public class VirtualClient implements IdObject {
	// The connection to this particular client
	RSocket socket;
	Vector<Body> bodiesToAdd;
	Vector<Body> bodiesToRem;
	Vector<Joint> jointsToAdd;
	Vector<Joint> jointsToRem;
	Vector<GameObject> gameObjectsToAdd;
	Vector<GameObject> gameObjectsToRem;
	Vector<GraphicsObject> graphicsObjectsToAdd;
	Vector<GraphicsObject> graphicsObjectsToRem;
	public Vector<int[]> bodiesToGos;
	public Vector<int[]> jointsToGos;
	public Vector<GroToGO> graphicsObjectsToGos;
	Vector<NetworkPackage> controlData;
	public long lastTimeInitSend;
	public boolean initialized;
	private int id = IdObject.DEFAULTID;
	public VirtualClient(RSocket socket) {
		this.socket = socket;
		bodiesToAdd = new Vector<Body>();
		bodiesToRem = new Vector<Body>();
		bodiesToGos = new Vector<int[]>();
		jointsToAdd = new Vector<Joint>();
		jointsToRem = new Vector<Joint>();
		jointsToGos = new Vector<int[]>();
		graphicsObjectsToAdd = new Vector<GraphicsObject>();
		graphicsObjectsToRem = new Vector<GraphicsObject>();
		graphicsObjectsToGos = new Vector<GroToGO>();
		gameObjectsToAdd = new Vector<GameObject>();
		gameObjectsToRem = new Vector<GameObject>();
		controlData = new Vector<NetworkPackage>();
	}
	public Vector<NetworkData> popData() {
		return socket.popData();
	}
	public void sendData(Vector<NetworkData> outgoing) {
		socket.sendData(outgoing);
	}
	public void sendData(NetworkData p) {
		Vector<NetworkData> singleDataVector = new Vector<NetworkData>();
		singleDataVector.add(p);
		sendData(singleDataVector);
	}
	public void sendUnsecure(Vector<NetworkData> outgoingFast) {
		socket.sendUnsecure(outgoingFast);
	}
	public void addBody(Body b, GameObject go) {
		bodiesToAdd.add(b);
		bodiesToGos.add(new int[]{go.id, b.id});
	}
	public void remBody(Body b, GameObject go) {
		bodiesToRem.add(b);
	}
	public void addJoint(Joint j, GameObject go) {
		jointsToAdd.add(j);
		jointsToGos.add(new int[]{go.id, j.id});
	}
	public void remJoint(Joint j, GameObject go) {
		jointsToRem.add(j);
	}
	public void addGraphicsObject(GraphicsObject o, GSync s, GameObject go) {
		graphicsObjectsToAdd.add(o);
		graphicsObjectsToGos.add(new GroToGO(go.id, o.id, s));
	}
	public void remGraphicsObject(GraphicsObject o, GameObject go) {
		graphicsObjectsToRem.add(o);
	}
	public void addGameObject(GameObject go) {
		gameObjectsToAdd.add(go);
	}
	public void remGameObject(GameObject go) {
		gameObjectsToRem.add(go);
	}
	@Override
	public int getId() {
		return id;
	}
	@Override
	public void setId(int id) {
		this.id = id;
	}
	@Override
	public void setIndexInList(int i) {
	}
	public void addControlData(NetworkPackage p) {
		controlData.add(p);
	}
}
